<?php

class CategoryModel extends CoreModel {

	function __construct()
	{
		parent::__construct();
	}

	public function getCategories($id)
	{
		$categories = array();
		$cats = get_the_category($id);
		foreach($cats as $category){
			$categories[] = array(
				'id'=>$category->term_id,
				'slug'=>$category->slug,
				'name'=>$category->cat_name,
				'link'=>get_category_link($category->term_id),
				'parent'=>$category->category_parent
			);
		}
		return $categories;
	}

	public function isCategoryReview($id)
	{
		$category = get_the_category($id);
		foreach($category as $cat){
			if($cat->term_id == CORE_CATEGORY_HOSTING_REVIEW){
				return true;
			}else{
				continue;
			}
		}
		return false;
	}

	public function getCategoryParent($id)
	{
		$category = get_the_category($id);
		foreach($category as $cat){
			if($cat->category_parent > 0){
				return $cat->category_parent;
			}else{
				continue;
			}
		}
		return 0;
	}

	public function countPostByCategory($category)
	{
		if(is_string($category)) {
			$catID = get_cat_ID($category);
		}else if(is_numeric($category)) {
			$catID = $category;
		}else{
			return 0;
		}
		$cat = get_category($catID);
		return $cat->count;
	}

}